from PySide6.QtWidgets import QDialog, QVBoxLayout, QLabel, QPushButton
from PySide6.QtCore import Qt
from src.config import app_config
from src.ui.i18n import _




class AboutDialog(QDialog):
    def __init__(self, translator, parent=None):
        super().__init__(parent)
        
        layout = QVBoxLayout(self)
        
        self.title_label = QLabel()
        self.title_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        font = self.title_label.font()
        font.setPointSize(20)
        font.setBold(True)
        self.title_label.setFont(font)
        
        self.version_label = QLabel()
        self.version_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        
        self.organization_label = QLabel()
        self.organization_label.setAlignment(Qt.AlignmentFlag.AlignCenter)

        layout.addWidget(self.title_label)
        layout.addWidget(self.version_label)
        layout.addWidget(self.organization_label)
        
        self.ok_button = QPushButton()
        self.ok_button.clicked.connect(self.accept)
        layout.addWidget(self.ok_button)
        
        self.setLayout(layout)
        
        self.retranslate_ui()
        if translator:
            translator.language_changed.connect(self.retranslate_ui)

    def retranslate_ui(self):
        app_name = app_config.get('app.name', 'Trans Video')
        self.setWindowTitle(_("About {}").format(app_name))
        self.title_label.setText(app_name)
        self.version_label.setText(_("Version: {}").format(app_config.get('app.version', '1.0.0')))
        self.organization_label.setText(_("Made by {} (baoge.org)").format("生生"))
        self.ok_button.setText(_("OK"))